package com.trf.fm1;

import java.util.Random;
import java.util.Scanner;

/**
 * @author 小小唐
 * @Date 2022/9/13-星期二-19:33
 */
public class Demo1 {

    static int N = 20;
    public static void main(String[] args) {
        int[] arr = new int[N];
        int x,n,i;
        int f = -1;

        Random r = new Random(); //随机种子
        for (i = 0; i < N; i++) {
            arr[i] = r.nextInt(100);//产生数组
        }

        System.out.print("随机生成的数据序列：\n");
        for (i = 0; i < N; i++) {
            System.out.println(arr[i]+" ");//输出序列
        }
        System.out.println("\n\n");

        System.out.println("输入要查找的整数：");
        Scanner input = new Scanner(System.in);
        x = input.nextInt();    //输入要查找的数
        for (i = 0; i < N; i++) {    //顺序查找
            if (x == arr[i]){        //找到数据
                f = i;
                break;
            }
        }

        if (f < 0){
            System.out.println("没有找到数据："+x);
        }else {
            System.out.println("数据"+x+"位于数组的第"+(f+1)+"个元素处.\n");
        }


    }
}
